/*
 * fh_rtc.h
 *
 *  Created on: Aug 26, 2016
 *      Author: duobao
 */

#ifndef FH_RTC_H_
#define FH_RTC_H_

#include <config.h>
#include <common.h>
#include <linux/string.h>
#include <rtc.h>
#include <asm/types.h>
#include <asm/arch/hardware.h>
#include <asm/io.h>
#include <asm/arch/platform.h>

/*
 * Registers offset
 */
#define  FH_RTC_COUNTER            0x0
#define  FH_RTC_OFFSET             0x4
#define  FH_RTC_POWER_FAIL         0x8
#define  FH_RTC_ALARM_COUNTER      0xC
#define  FH_RTC_INT_STAT           0x10
#define  FH_RTC_INT_EN             0x14
#define  FH_RTC_SYNC               0x18
#define  FH_RTC_DEBUG              0x1C
#define  FH_RTC_USER_REG           0x20

#define SEC_BIT_START		0
#define SEC_VAL_MASK		0x3f

#define MIN_BIT_START		6
#define MIN_VAL_MASK		0xfc0

#define HOUR_BIT_START		12
#define HOUR_VAL_MASK		0x1f000

#define DAY_BIT_START		17
#define DAY_VAL_MASK		0xfffe0000

#define FH_RTC_ISR_SEC_POS  	1<<0
#define FH_RTC_ISR_MIN_POS  	1<<1
#define	FH_RTC_ISR_HOUR_POS  	1<<2
#define	FH_RTC_ISR_DAY_POS  	1<<3
#define	FH_RTC_ISR_ALARM_POS    1<<4
#define	FH_RTC_ISR_SEC_MASK 	1<<27
#define	FH_RTC_ISR_MIN_MASK 	1<<28
#define	FH_RTC_ISR_HOUR_MASK 	1<<29
#define	FH_RTC_ISR_DAY_MASK 	1<<30
#define	FH_RTC_ISR_ALARM_MASK 	1<<31

// input: val=fh_rtc_get_time(base_addr)
#define FH_GET_RTC_SEC(val)		 ((val & SEC_VAL_MASK) >> SEC_BIT_START)
#define FH_GET_RTC_MIN(val)		 ((val & MIN_VAL_MASK) >> MIN_BIT_START)
#define FH_GET_RTC_HOUR(val)     ((val & HOUR_VAL_MASK) >> HOUR_BIT_START)
#define FH_GET_RTC_DAY(val)	 	 ((val & DAY_VAL_MASK) >> DAY_BIT_START)

struct fh_rtc_platform_data
{
	u32 clock_in;
	char *clk_name;
	char *dev_name;
	u32 base_year;
	u32 base_month;
	u32 base_day;
};
enum
{
	init_done=1,
	initing=0

};

#endif /* FH_RTC_H_ */
